home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 7 / BBS in a Box - Macintosh - Volume VII (BBS in a Box) (January 1993).iso / Files / Prog / M / M2TSkel.cpt / M2TSkel / MultiSkelZoom.MOD / MultiSkelZoom.MOD
Encoding:
Modula Implementation  |  1987-04-17  |  4.2 KB  |  203 lines  |  [TEXT/MPS ]

  1. IMPLEMENTATION MODULE MultiSkelZoom;
  2.  
  3. (*
  4.  *    © Paul DuBois, 14 June 1986
  5.  *        TML Modula-2 version, Dennis Cohen, 15 April 1987
  6.  *)
  7.  
  8. FROM SYSTEM IMPORT ADDRESS;
  9. FROM QuickDraw IMPORT Rect, Point, BackPat, PenMode, black, patXor, Random,
  10.                                             SetRect, FrameRect, SetPt, Pt2Rect, InvertRect,
  11.                                             EraseRect, notPatCopy;
  12. FROM EventManager IMPORT StillDown;
  13. FROM MenuManager IMPORT EnableItem, DisableItem, DrawMenuBar;
  14. FROM WindowManager IMPORT WindowPtr, WindowPeek, GetNewWindow, CloseWindow;
  15. FROM MultiSkelGlobals IMPORT zoomWindRes, editMenu, SetWindClip, ResetWindClip,
  16.                                                          DrawGrowBox, zoomWind;
  17. FROM TransSkel IMPORT SkelWindow, WKeyProc, WCloseProc;
  18.  
  19. CONST
  20.     zoomSteps = 15;
  21.  
  22. VAR
  23.     zRect: ARRAY [0..zoomSteps-1] OF Rect;
  24.     zSrcRect: Rect;
  25.     sizeX, sizeY: INTEGER;
  26.  
  27.  
  28. PROCEDURE Rand(max: INTEGER): INTEGER;
  29.  
  30.     VAR
  31.         t: INTEGER;
  32.  
  33. BEGIN
  34.     t := Random();
  35.     t := ABS(t);
  36.     RETURN (t MOD (max+1));
  37. END Rand;
  38.  
  39.  
  40. PROCEDURE ZoomRect(r1, r2: Rect);
  41.  
  42.     VAR
  43.         r1left, r1top: INTEGER;
  44.         l, t: INTEGER;
  45.         j: INTEGER;
  46.         hDiff, vDiff, widDiff, htDiff: INTEGER;
  47.         r, b: INTEGER;
  48.         rWid, rHt: INTEGER;
  49.  
  50. BEGIN
  51.     r1left := r1.left;
  52.     r1top := r1.top;
  53.     hDiff := r2.left-r1.left;
  54.     vDiff := r2.top-r1.top;
  55.     rWid := r1.right-r1.left;
  56.     rHt := r1.bottom-r1.top;
  57.     widDiff := (r2.right-r2.left) - rWid;
  58.     htDiff := (r2.bottom-r2.top) - rHt;
  59.     (*
  60.         order of evaluation is important in the rect coordinate calculations.
  61.         Since all arithmetic is integer, you can't save time by calculating
  62.         j DIV zoomSteps and using that — it'll usually be 0.
  63.     *)
  64.     FOR j := 1 TO zoomSteps DO
  65.         FrameRect(zRect[j-1]);            (* Erase a rectangle *)
  66.         l := r1left + (hDiff*j) DIV zoomSteps;
  67.         t := r1top + (vDiff*j) DIV zoomSteps;
  68.         r := l + rWid + (widDiff*j) DIV zoomSteps;
  69.         b := t + rHt + (htDiff*j) DIV zoomSteps;
  70.         SetRect(zRect[j-1], l, t, r, b);
  71.         FrameRect(zRect[j-1]);
  72.     END;
  73. END ZoomRect;
  74.  
  75.  
  76. PROCEDURE ZoomMain;
  77.  
  78.     VAR
  79.         i: INTEGER;
  80.         pt1, pt2: Point;
  81.         dstRect: Rect;
  82.  
  83. BEGIN
  84.     SetPt(pt1, Rand(sizeX), Rand(sizeY));        (* Generate a new rect *)
  85.     SetPt(pt2, Rand(sizeX), Rand(sizeY));        (* and zoom to it *)
  86.     Pt2Rect(pt1, pt2, dstRect);
  87.     SetWindClip(zoomWind);
  88.     ZoomRect(zSrcRect, dstRect);
  89.     ResetWindClip;
  90.     zSrcRect := dstRect;
  91. END ZoomMain;
  92.  
  93.  
  94. PROCEDURE ZoomMouse(thePt: Point; t: LONGINT; mods: BITSET);
  95.  
  96. BEGIN
  97.     WHILE StillDown() DO (* Sit and wait *) ; END;
  98. END ZoomMouse;
  99.  
  100.  
  101. (*
  102.     Draw the growbox in white on black.  Tricky: if the window is inactive, the
  103.     grow box will be drawn black, as it should be.  But, if the window is active,
  104.     it will STILL be drawn black on white!  So, have to check whether the window
  105.     is active.  The test for active has to be done carefully since the window
  106.     manager stores 255 for true and 0 for false rather than 1 & 0.
  107. *)
  108.  
  109. PROCEDURE ZDrawGrowBox;
  110.  
  111.     VAR
  112.         r: Rect;
  113.         aPeek: WindowPeek;
  114.  
  115. BEGIN
  116.     PenMode(notPatCopy);
  117.     DrawGrowBox(zoomWind);
  118.     PenMode(patXor);
  119.     aPeek := VAL(WindowPeek, zoomWind);
  120.     IF aPeek^.hilited THEN
  121.         r := zoomWind^.portRect;
  122.         r.left := r.right - 14;
  123.         r.top := r.bottom - 14;
  124.         InvertRect(r);
  125.     END;
  126. END ZDrawGrowBox;
  127.  
  128.  
  129. PROCEDURE SetZoomSize;
  130.  
  131.     VAR
  132.         r: Rect;
  133.  
  134. BEGIN
  135.     r := zoomWind^.portRect;
  136.     DEC(r.right, 15);
  137.     sizeX := r.right;
  138.     sizeY := r.bottom;
  139. END SetZoomSize;
  140.  
  141.  
  142. PROCEDURE ZoomUpdate(resized: BOOLEAN);
  143.  
  144.     VAR
  145.         i: INTEGER;
  146.  
  147. BEGIN
  148.     EraseRect(zoomWind^.portRect);
  149.     ZDrawGrowBox;
  150.     SetWindClip(zoomWind);
  151.     FOR i := 1 TO zoomSteps DO
  152.         FrameRect(zRect[i-1]);
  153.     END;
  154.     ResetWindClip;
  155.     IF resized THEN SetZoomSize; END;
  156. END ZoomUpdate;
  157.  
  158.  
  159. PROCEDURE ZoomActivate(active: BOOLEAN);
  160.  
  161. BEGIN
  162.     ZDrawGrowBox;
  163.     IF active THEN DisableItem(editMenu, 0);
  164.     ELSE EnableItem(editMenu, 0);
  165.     END;
  166.     DrawMenuBar;
  167. END ZoomActivate;
  168.  
  169.  
  170. PROCEDURE ZoomHalt;
  171.  
  172. BEGIN
  173.     CloseWindow(zoomWind);
  174. END ZoomHalt;
  175.  
  176.  
  177. PROCEDURE ZoomInit;
  178.  
  179.     VAR
  180.         i: INTEGER;
  181.  
  182. BEGIN
  183.     zoomWind := GetNewWindow(zoomWindRes, VAL(ADDRESS, NIL), VAL(WindowPtr, -1D));
  184.     SkelWindow(zoomWind,
  185.                          ZoomMouse,                (*    Pause while button down *)
  186.                          VAL(WKeyProc, NIL),
  187.                          ZoomUpdate,
  188.                          ZoomActivate,
  189.                          VAL(WCloseProc, NIL),
  190.                          ZoomHalt,
  191.                          ZoomMain,                (* Draw a new series *)
  192.                          TRUE);                        (* But only if the front window *)
  193.     SetZoomSize;
  194.     BackPat(black);
  195.     PenMode(patXor);
  196.     SetRect(zSrcRect, 0, 0, 0, 0);
  197.     FOR i := 0 TO zoomSteps - 1 DO
  198.         zRect[i] := zSrcRect;
  199.     END;
  200. END ZoomInit;
  201.  
  202. END MultiSkelZoom.
  203.